package test19.reader_;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class BufferedReader_ {
    public static void main(String[] args) throws IOException {
        String filePath = "D:\\story.txt";
        BufferedReader bufferedReader = null;

        try {
            bufferedReader = new BufferedReader(new FileReader(filePath));
            String line = "";//按行读取, 效率高
            //1. bufferedReader.readLine() 是按行读取文件
            //2. 当返回null 时，表示文件读取完毕
            while ((line = bufferedReader.readLine()) != null){
                System.out.println(line);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } finally {
            //关闭流, 这里注意，只需要关闭 BufferedReader ，因为底层会自动的去关闭 节点流
            bufferedReader.close();
        }
    }
}
